package com.zygh.lz.controller;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.zygh.lz.dao.SignMapper;
import com.zygh.lz.entity.Coordinate;
import com.zygh.lz.service.PatrolrecordService;
import com.zygh.lz.stapprove.ResultUtil;
import com.zygh.lz.vo.ResultBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
public class Gpis {

    @Resource
    private PatrolrecordService patrolrecordService;
    @Resource
    private SignMapper signMapper;

    /**
     * 查询所有坐标轨迹(根据警号)
     */
    @GetMapping("findInfoByPolice")
    public List<Coordinate> findInfoByPolice(String police) {
        List<Coordinate> coordinateList = new ArrayList<>();
        System.out.println(police);
        try {
            String result1 = HttpUtil.get("http://localhost:8099/findInfoByPolice?police=" + police);
            JSONArray qdMap = JSONArray.parseArray(result1);
            for (int i = 0; i < qdMap.size(); i++) {
                Coordinate coordinate = new Coordinate();
                coordinate.setId(qdMap.getJSONObject(i).getString("id"));
                coordinate.setPolice(qdMap.getJSONObject(i).getString("police"));
                coordinate.setCreattime(qdMap.getJSONObject(i).getString("creattime"));
                coordinate.setLonLats(qdMap.getJSONObject(i).getString("lonLats"));
                coordinateList.add(coordinate);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return coordinateList;
    }

    @ApiOperation("根据人员id和巡查id查询GPS轨迹坐标")
    @GetMapping("selectGPSById")
    public ResultBean selectGPSById(Integer staffId, String startTime, String endTime) {
        return patrolrecordService.selectGPSById(staffId, startTime, endTime);
    }




}

